﻿using LD.Host;
using System;
using System.Data;
using System.Linq;

namespace LD.Tool
{
    public partial class FrmToolBaseSkip : FrmToolBase
    {
        public FrmToolBaseSkip()
        {
            InitializeComponent();
            this.Shown += FrmToolBaseSkip_Shown;
        }

        private void FrmToolBaseSkip_Shown(object sender, EventArgs e)
        {
            Init();
            this.btn_ok.Click += Btn_ok_Click;
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            this.TB_Tool.FailSkip = FailSkip;
            this.TB_Tool.SkipFlow = this.cob_flow.Text;
            this.TB_Tool.EchoPLC.IsEcho = this.chk_echoPlc.Checked;
            this.TB_Tool.EchoPLC.Address = this.txt_plcAdr.Text;
            this.TB_Tool.EchoPLC.Val = this.txt_plcVal.Text;
            this.TB_Tool.EchoPLC.DataType = "Int16";
        }

        private void Init()
        {
            if (Appbus.PartNo == null)
                return;
            if (Appbus.PartNo.Config == null)
                return;

            var flow = Appbus.PartNo.Config.Flow.Where(p => p.FlowType == 1).OrderBy(p => p.Sort).ToList();
            if (flow != null && flow.Count > 0)
            {
                foreach (var item in flow)
                {
                    this.cob_flow.Items.Add(item.Name);
                }
            }
            this.sw_failSkip.Checked = this.TB_Tool.FailSkip;
            this.cob_flow.Text = this.TB_Tool.SkipFlow;
            this.txt_plcAdr.Text = this.TB_Tool.EchoPLC.Address;
            this.txt_plcVal.Text = this.TB_Tool.EchoPLC.Val;
            this.chk_echoPlc.Checked = this.TB_Tool.EchoPLC.IsEcho;
        }
        public bool FailSkip
        {
            get
            {
                return this.sw_failSkip.Checked;
            }
        }
    }
}
